//1379. 找出克隆二叉树中的相同节点

//本质就是找到original树中target节点
//因为cloned树是克隆original树的，因此两个树节点都相同
//因此让original与cloned树并行，当original找到target节点时，cloned也就找到了

#include <iostream>
using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution {
public:
    TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target) {
        if(original == NULL) return NULL;
        //递归结束判断
        if(original == target) return cloned;

        //递归语句
        TreeNode* left = getTargetCopy(original->left, cloned->left, target);
        TreeNode* right = getTargetCopy(original->right, cloned->right, target);

        if(left) return left;
        else return right;
    }
};